class SRKFWeaponPickup extends KFWeaponPickup
	placeable;

var       string         OwnerName;
replication
{
	reliable if(Role == ROLE_Authority)
		OwnerName;
}

function InitDroppedPickupFor(Inventory Inv)
{
	local SRKFWeapon W;
	local Inventory InvIt;
	local byte bSaveAmmo[2];
	local int m;

	W = SRKFWeapon(Inv);
	if (W != None)
	{
		//Check if any other weapon is using the same ammo
		for(InvIt = W.Owner.Inventory; InvIt!=none; InvIt=InvIt.Inventory)
		{
			if(Weapon(InvIt)!=none && InvIt!=W)
			{
				for(m=0; m < 2; m++)
				{
					if(Weapon(InvIt).AmmoClass[m] == W.AmmoClass[m])
						bSaveAmmo[m] = 1;
				}
			}
		}
		if(bSaveAmmo[0]==0)
		{
			MagAmmoRemaining = W.MagAmmoRemaining;
			AmmoAmount[0] = W.AmmoAmount(0);
			//Log("MagAmmoRemaining="$MagAmmoRemaining@"AmmoAmount="$AmmoAmount[0]);
		}
		if(bSaveAmmo[1]==0)
			AmmoAmount[1] = W.AmmoAmount(1);

		SellValue = W.SellValue;
	}
	OwnerName=W.OwnerName;
	//Log("PrevOwner="$OwnerName);
	SetPhysics(PHYS_Falling);
	GotoState('FallingPickup');
	Inventory = Inv;
	bAlwaysRelevant = false;
	bOnlyReplicateHidden = false;
	bUpdateSimulatedPosition = true;
	bDropped = true;
	bIgnoreEncroachers = false; // handles case of dropping stuff on lifts etc
	NetUpdateFrequency = 8;
	bNoRespawn = true;

	if ( KFWeapon(Inventory) != none && KFWeapon(Inventory).bIsTier2Weapon && !KFWeapon(Inventory).bPreviouslyDropped &&
		 PlayerController(Pawn(Inventory.Owner).Controller) != none )
	{
		KFWeapon(Inventory).bPreviouslyDropped = true;
	}
}

function bool CheckCanCarry(KFHumanPawn Hm)
{
	local SRPlayerReplicationInfo SRPRI;
	local Controller C;
	for( C = Level.ControllerList; C != None; C = C.nextController ) 
	{
		if( C.IsA('PlayerController') && C.PlayerReplicationInfo.PlayerName~=OwnerName)
		{
			SRPRI = SRPlayerReplicationInfo(C.PlayerReplicationInfo);
		}
	}
	//Log(OwnerName@Hm.OwnerName@SRPRI@SRPRI.AllowWeaponsPickup);
	//if(SRPRI!=none)
		//Log("CheckCanCarry"@OwnerName@Hm.OwnerName@SRPRI.AllowWeaponsPickup@SRPRI.PlayerName);
	if(	OwnerName~=Hm.OwnerName || !CheckIfOnTheServer(OwnerName) || (SRPRI!=none && SRPRI.AllowWeaponsPickup))
	{
		return Super.CheckCanCarry(Hm);
	}
	return false;
}

function bool CheckIfOnTheServer(string _name)
{
	local Controller C;
	for( C = Level.ControllerList; C != None; C = C.nextController ) 
	{
		if( C.PlayerReplicationInfo!=None && C.PlayerReplicationInfo.PlayerName~=_name )
		{
			return true;
		}
	}
	return false;
}

defaultproperties
{
}
